import request from '@/utils/request';
import { ListParams } from './data';
import { formatCurrentStateData } from '@/helpers/RequestHelper';

const API = '/api/admin/menu';
const API_TWO = '/api/admin/menuperm';

export async function queryRule(params?: ListParams) {
  return request(`${API}/index`, {
    params,
  })?.then(
    (response):any => formatCurrentStateData(response)
  ).catch((error) => {})
}

export async function removeRule(params: {ids:string}) {
  return request(`${API}/destroy`, {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  })?.then((response) => {
    return response;
  });
}

export async function addRule(params: ListParams) {
  return request(`${API}/store`, {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  })?.then((response) => {
    return response;
  });
}

export async function updateRule(params: ListParams) {
  return request(`${API}/update`, {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  })?.then((response) => {
    return response;
  });
}


export async function queryItemRule(params?: ListParams) {
  return request(`${API_TWO}/index`, {
    params,
  })?.then(
    (response):any => formatCurrentStateData(response)
  ).catch((error) => {})
}

export async function addItemRule(params: ListParams) {
  return request(`${API_TWO}/store`, {
    method: 'POST',
    data: {
      ...params,
      method: 'post',
    },
  });
}

export async function removeItemRule(params: {ids:string}) {
  return request(`${API_TWO}/destroy`, {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  });
}

export async function updateItemRule(params: ListParams) {
  return request(`${API_TWO}/update`, {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}


